package part13;

import java.util.Formatter;

/**
 * @author wcj
 * @Date 2021/5/24 16:05
 * @Version 1.0
 */
public class Part136 {

    private double total = 0;
    private Formatter f = new Formatter(System.out);

    private void printTitle() {
        f.format("%-5s %5s %10s\n", "Item", "Qty", "Price");
        f.format("%-5s %5s %10s\n", "----", "---", "-----");
    }

    private void print(String name, int qty, double price) {
        f.format("%-5s %5d %10.2f\n", name, qty, price);
        total += price;
    }

    private void printTotal() {
        f.format("%-5s %5s %10.2f\n", "Tax", "", total * 0.6);
        f.format("%-5s %5s %10s\n", "", "", "-----");
        f.format("%-5s %5s %10.2f\n", "Total", "", total * 1.06);
    }

    /**
     * 格式化说明符：java默认的对齐方式为右对齐，通过-可以修改对齐方式
     * d---十进制整数，c---字符，b---boolean类型，s---字符串，f---浮点数
     * e---科学计数浮点数，x---十六进制整数，h---十六进制散列码
     * 数字在整数位表明限制宽度，在小数位表明限制小数点后位数
     *
     * @param args
     */
    public static void main(String[] args) {
        Part136 part126 = new Part136();
        part126.printTitle();
        part126.print("wcj", 4, 4.25);
        part126.print("bss", 3, 5.1);
        part126.printTotal();
    }
}
